package com.maoyue.demo.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.ListUtils;
import com.maoyue.demo.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("wangyu")
public class WangYuController {

    String PATH = "C:\\Users\\86177\\java_01\\day03\\excel-demo";

    private List<User> data() {
        List<User> list = ListUtils.newArrayList();
        for (int i = 0; i < 10; i++) {
            User data = new User();
            data.setPassword("123" + i);
            data.setUserId(i);
            data.setUserName("rose" + i);
            list.add(data);
        }
        return list;
    }

    /**
     * 写
     * @return ok
     */
    @GetMapping("write")
    public String write(){
        String fileName = PATH + "wangyuFile.xlsx";
        EasyExcel.write(fileName,User.class).sheet("yuu").doWrite(data());
        return "ok";
    }

}
